
class Code extends Code3a {
    private static boolean error = false;
    public Code() {
        super();
    }

    public Code(Inst3a i) {
        super(i);
    }


    public static Code genBinOp(int op, Expratt exp1, Expratt exp2, Operand3a temp) {
        Code cod = exp1.code;
        cod.append(exp2.code);
        cod.append(new Inst3a(Inst3a.TAC_VAR, temp, null, null));
        Inst3a i = new Inst3a(op, temp, exp1.place, exp2.place);
        cod.append(new Code(i));

        return cod;
    }

    public static Code genJumpIfz(Expratt exp, Tokatt label) {
        Code cod = exp.code;
        cod.append(new Inst3a(Inst3a.TAC_IFZ, exp.place, label, null));

        return cod;
    }

    public static Code genGoto(Tokatt label) {
        Code cod = new Code(new Inst3a(Inst3a.TAC_GOTO, label, null, null));

        return cod;
    }

    public static Code genLabel(Tokatt label) {
        Code cod = new Code(new Inst3a(Inst3a.TAC_LABEL, label, null, null));

        return cod;
    }

    public static Code genVar(Tokatt name) {
        Code cod = new Code(new Inst3a(Inst3a.TAC_VAR, name, null, null));

        return cod;
    }

    public static Code genCopy(Tokatt ident, Expratt exp) {
        Code cod = exp.code;
        cod.append(new Inst3a(Inst3a.TAC_COPY, ident, exp.place, null));

        return cod;
    }

    public static Code genArg(Tokatt arg) {
        Code cod = new Code(new Inst3a(Inst3a.TAC_ARG, arg, null, null));

        return cod;
    }

    public static Code genCall(String name, Tokatt ret) {
        Tokatt fun = new Tokatt(name, TypeSystem.TypeLabel());

        return genCall(fun, ret);
    }

    public static Code genCall(Tokatt fun, Tokatt ret) {
        Code cod = new Code(new Inst3a(Inst3a.TAC_CALL, ret, fun, null));

        return cod;
    }
    
    public static Code genTabVar(Tokatt var, Tabatt tab) {
        Code cod = tab.code;
        cod.append(new Inst3a(Inst3a.TAC_TABVAR, var, tab.place, tab.expression));

        return cod;
    }

    public static Code genVarTab(Tabatt tab, Tokatt var) {
        Code cod = tab.code;
        cod.append(new Inst3a(Inst3a.TAC_VARTAB, tab.place, tab.expression, var));

        return cod;
    }

    public static Code genReturn(Expratt exp) {
        Code cod = exp.code;
        cod.append(new Inst3a(Inst3a.TAC_RETURN, exp.place, null, null));

        return cod;
    }

} // Code ***
